package com.jing.cloud.client;

import com.alibaba.fastjson.JSON;
import com.jing.cloud.service.Req;

public class Request {
    public static final int ROUTE_MODE_RANDOM = 0;//随机
    public static final int ROUTE_MODE_NAMED = 1;//指定实例

    //调用者获取所有实例名，然后循环调用。不提供广播调用模式
//    public static final int ROUTE_MODE_BROADCAST = 99;

    private String serviceName;
    private String methodName;
    private Object param;
    private String reqId;
    private String version;
    private long userId;
    private boolean oneway = false;
    private String instanceName;
    private int routeMode = ROUTE_MODE_RANDOM;

    public Req toReq() {
        Req req = new Req();
        req.setMethodName(this.methodName);
        req.setParam(JSON.toJSONString(this.param));
        req.setReqId(this.reqId);
        req.setUserId(this.userId);
        return req;
    }

    public String getInstanceName() {
        return instanceName;
    }

    public Request setInstanceName(String instanceName) {
        this.instanceName = instanceName;
        return this;
    }

    public int getRouteMode() {
        return routeMode;
    }

    public Request setRouteMode(int routeMode) {
        this.routeMode = routeMode;
        return this;
    }

    public boolean isOneway() {
        return oneway;
    }

    public Request setOneway(boolean oneway) {
        this.oneway = oneway;
        return this;
    }

    public String getServiceName() {
        return serviceName;
    }

    public Request setServiceName(String serviceName) {
        this.serviceName = serviceName;
        return this;
    }

    public String getMethodName() {
        return methodName;
    }

    public Request setMethodName(String methodName) {
        this.methodName = methodName;
        return this;
    }

    public Object getParam() {
        return param;
    }

    @Override
    public String toString() {
        return "Request{" +
                "serviceName='" + serviceName + '\'' +
                ", methodName='" + methodName + '\'' +
                ", param=" + param +
                ", reqId='" + reqId + '\'' +
                ", version='" + version + '\'' +
                ", userId=" + userId +
                ", oneway=" + oneway +
                ", instanceName='" + instanceName + '\'' +
                ", routeMode=" + routeMode +
                '}';
    }

    public Request setParam(Object param) {
        this.param = param;
        return this;
    }

    public String getReqId() {
        return reqId;
    }

    public Request setReqId(String reqId) {
        this.reqId = reqId;
        return this;
    }


    public String getVersion() {
        return version;
    }

    public Request setVersion(String version) {
        this.version = version;
        return this;
    }

    public long getUserId() {
        return userId;
    }

    public Request setUserId(long userId) {
        this.userId = userId;
        return this;
    }

}
